package com.example.mediaservice;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ScreenBroadcastReceiver extends BroadcastReceiver {
    private static final String TAG = "ScreenReceiver";
    private OnScreenStateChangedListener listener;

    // 定义回调接口，用于通知服务处理锁屏事件
    public interface OnScreenStateChangedListener {
        void onScreenOff(); // 锁屏时回调
        void onScreenOn();  // 亮屏时回调
    }

    public ScreenBroadcastReceiver(OnScreenStateChangedListener listener) {
        this.listener = listener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (Intent.ACTION_SCREEN_OFF.equals(action)) {
            Log.d(TAG, "屏幕关闭（锁屏）");
            if (listener != null) {
                listener.onScreenOff(); // 通知服务处理锁屏逻辑
            }
        } else if (Intent.ACTION_SCREEN_ON.equals(action)) {
            Log.d(TAG, "屏幕点亮");
            if (listener != null) {
                listener.onScreenOn();
            }
        }
    }
}